package com.trjcn.wxshare.utils;

import okhttp3.FormBody;
import okhttp3.RequestBody;
import org.springframework.util.ReflectionUtils;


public class DataBuildUtil {

    public static RequestBody getReqBody(Object object){
        FormBody.Builder requestBody = new FormBody.Builder();
        ReflectionUtils.doWithFields(object.getClass(), field -> {
            // 设置字段可反射
            if (!field.isAccessible()) {
                field.setAccessible(true);
            }
            // 排除字段为空的情况
            if (field.get(object) == null) {
                return;
            }
            requestBody.add(field.getName(), field.get(object).toString());
        });
        return requestBody.build();
    }
}
